if(!dojo._hasResource["market.widgets.component.Album"]){dojo._hasResource["market.widgets.component.Album"]=true;
require(["dojo/_base/declare", "market/widgets/CommonWidget","dojo/query"],function(declare,_widget,query){
declare("market.widgets.component.Album",[_widget],{
_templateHTML:'<div style="padding:5px;"><div class="nickNameHeader1">{label1}</div>'+((participant.isGuest)?'':'<div class="sub_menu_title_right"><a href="#" id="hrefAttachFile">{label2}</a></div>')+'<div class="clear"></div>{albumsHTML}</div>',
_albumsHTML:'<div><div class="box_album" name="div_box_album"><div class="box_album_title">{name}</div><div class="box_album_content"><input type="hidden" value="{uuid}"/>{picturesHTML}</div></div></div>',
_picturesHTML:'<img alt="" src="getContent/{uuid}/medium" class="box_picture"/>',
_ADD_FORM:"market.widgets.component.Album.Add",
_dataSource:{},_currentForm:null,_attachedEvent:null,targetNode:null,hasAttached:false,
showAlbums:function(){
   this.hasAttached=false;
   this._show();
},
showAttached:function(){
   this.hasAttached=true;
   this._show();
},
getAlbums:function(){
   return this._dataSource.albums;
},
showAddForm:function(){
   var handleEvents = {click:this._handleClickEvents()};
   this._currentForm = this.createForm(this._ADD_FORM,this.targetNode,'participant/'+participant.id+'/album/add',null,handleEvents,null);
},
addAlbum:function(){
   var handleSuccess=function(data){
      SYSTEMWIDGET.messageWidget().showSucc(data.messageSucc);
      SYSTEMWIDGET.album().showAlbums();
   };
   this._currentForm.callSaveForm({handleSuccess:handleSuccess});
},
handleAttached:function(callFunction){
   this._attachedEvent=callFunction;
},
attachPictures:function(){
   var backupEvent=this._attachedEvent; 
   this._attachedEvent();
   this.showAlbums();
   this._attachedEvent=backupEvent;
},
initialShowAlbums:function(dataSource){
   this._dataSource=dataSource;
   this._parserTemplateHTML();
   var widget=this;
   query('#hrefAttachFile').onclick(function(){
      SYSTEMWIDGET.pictures({contentId:widget.targetNode}).viewUploadFiles();
   });
   query('div[name="div_box_album"]').onclick(function(){
      var albumUUID = dojo.query('input[type="hidden"]', this)[0].value;
      SYSTEMWIDGET.showPictures({contentId:widget.targetNode,albumUUID:albumUUID,hasAttached:widget.hasAttached}).showPictures();
   });
},
_show:function(){
   this._attachedEvent=null;
   var args = {ajaxUrl: 'participant/'+participant.id+'/albums',contentId:this.targetNode,callback:function(data){
      SYSTEMWIDGET.album().initialShowAlbums(data);
   }};
   SYSTEMWIDGET.ajaxWidget(args).callXhrGetJson();
},
_parserTemplateHTML:function(){
   this._dataSource.albumsHTML=this._parseAlbumsHTML();
   var templateHTML=dojo.replace(this._templateHTML,this._dataSource);
   templateHTML+='<div class="clear"></div>';
   dojo.html.set(this.targetNode,templateHTML,{parseContent: true});
},
_parseAlbumsHTML:function(){
   var albums=this._dataSource.albums;
   var templateHTML='';
   for(var index=0;index<albums.length;index++){
      var album=albums[index];
      album.picturesHTML=this._parsePicturesHTML(album.files);
      templateHTML+=dojo.replace(this._albumsHTML, album);
   }
   return templateHTML;
},
_parsePicturesHTML:function(files){
   var templateHTML='';
   for(var index=0;index<files.length;index++){
      templateHTML+=dojo.replace(this._picturesHTML, files[index]);
   }
   return templateHTML;
},
_handleClickEvents: function(){
   var clickEvents = {events:['btnCancel','btnAdd'],
      btnCancel:function(data){
         SYSTEMWIDGET.album().showAlbums();},
      btnAdd:function(data){
         SYSTEMWIDGET.album().addAlbum();
      }
   };
   return clickEvents;
}
});});}


